package com.wechat.back.controller;

import com.wechat.back.anno.OptLog;
import com.wechat.back.pojo.tools.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.wechat.back.service.BgService;
import com.wechat.back.pojo.pic.Bg;
import java.util.List;

@RestController
@RequestMapping("/bg")
public class BackgroundController {
    @Autowired
    private BgService BgService;


    @GetMapping("/list")
    public Result<List<Bg>> list(
            @RequestParam(required = false) String bgType
    ){
        List<Bg> Bg = BgService.list(bgType);
        return Result.success(Bg);
    }

    @OptLog(optModule = "背景图片模块",optType = "添加", optDesc = "添加背景图片")
    @PostMapping("/add")
    public Result add(@RequestBody @Validated(Bg.Add.class) Bg bg){
        BgService.add(bg);
        return Result.success();
    }

    @OptLog(optModule = "背景图片模块",optType = "修改", optDesc = "修改背景图片")
    @PutMapping
    public Result update(@RequestBody @Validated(Bg.Update.class) Bg bg){
        BgService.update(bg);
        return Result.success();
    }

    @OptLog(optModule = "背景图片模块",optType = "删除", optDesc = "删除背景图片")
    @DeleteMapping
    public Result delete(Integer bgId){
        BgService.delete(bgId);
        return Result.success();
    }
}
